package cn.wei.sdd.core.controller.admin;


import cn.wei.common.result.R;
import cn.wei.sdd.base.util.JwtUtils;
import cn.wei.sdd.core.pojo.query.OutWarehouseQuery;
import cn.wei.sdd.core.pojo.vo.OutWarehouseListVO;
import cn.wei.sdd.core.pojo.vo.OutWarehouseVO;
import cn.wei.sdd.core.service.OutWarehouseService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 出库记录表 前端控制器
 * </p>
 *
 * @author Wei
 * @since 2021-11-04
 */
@RestController
@Api(tags = "出库管理")
@RequestMapping("/admin/core/outWarehouse")
public class AdminOutWarehouseController {

    @Resource
    private OutWarehouseService outWarehouseService;

    @ApiOperation("出库")
    @PostMapping("outWarehouse")
    public R outWarehouse(@RequestBody OutWarehouseVO outWarehouseVO, HttpServletRequest request){

        String token = request.getHeader("token");
        Long userId = JwtUtils.getUserId(token);
        outWarehouseService.outWarehouse(outWarehouseVO,userId);
        return R.ok().message("出库成功");
    }

    @ApiOperation("出库记录列表")
    @GetMapping("/outWarehouseList/{page}/{limit}")
    public R listPage(
            @ApiParam(value = "当前页码",required = true)
            @PathVariable("page") Long page,
            @ApiParam(value = "每页记录数",required = true)
            @PathVariable("limit") Long limit,
            @ApiParam(value = "搜索对象",required = true)
                    OutWarehouseQuery outWarehouseQuery){

        Page<OutWarehouseListVO> pageParam = new Page<>(page,limit);
        IPage<OutWarehouseListVO> pageModel =  outWarehouseService.listPage(pageParam,outWarehouseQuery);
        return R.ok().data("pageModel",pageModel);
    }



}

